#include <stdio.h>
#include <stdlib.h>
#include "string.h"
#include "math.h"

#include "doge_cmd.h"


static void led_cmd_callback(int argc, char **argv)
{
    int i = 0;

	if (argc != 2)
	{
		printf("Usage: LED <1/0>\r\n");
		return;
	}

    int state = atoi(argv[1]);
	if (state == 0)
	{
		printf("LED OFF\r\n");
	}
	else
	{
		printf("LED ON\r\n");
	}
}

static void freq_cmd_callback(int argc, char **argv)
{
    int i = 0;

    printf("cmd %s, argc %d\r\n", argv[0], argc);

    for (i = 1; i < argc; i++)
        printf("argv[%d] %s\t", i, argv[i]);

    printf("\r\n");

    int num1 = atoi(argv[1]);
    int num2 = atoi(argv[2]);
    printf("num1 = %d num2 = %d\r\n", num1, num2);
}

doge_cmd_t  d_cmd_list[] = {
	{.cmd = "LED", .cb = led_cmd_callback},
	{.cmd = "FREQ", .cb = freq_cmd_callback},
};

int _str_cmp(char *str1, char *str2);

int main(void)
{
	char str[] = "             LED 1";
	char str2[] = " FREQ 5 3";
	char str3[] = "             LED 0";

	doge_cmd_parse(str, d_cmd_list, DOGE_CMD_COUNTOF(d_cmd_list));
	doge_cmd_parse(str3, d_cmd_list, DOGE_CMD_COUNTOF(d_cmd_list));

	printf("\r\n");
	
	doge_cmd_parse(str2, d_cmd_list, DOGE_CMD_COUNTOF(d_cmd_list));

	return 0;
}
